﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tool
{
    class Program
    {
        static void Main(string[] args)
        {
            IList<string> mailTo = new List<string>();
            IList<string> mailCC = new List<string>();
            string subject = string.Empty, logDir = string.Empty;
            string userName = string.Empty, password = string.Empty, domain = string.Empty;
            
            if (args.Count() == 0 || args[0].Equals("/?") || args[0].IndexOf("help", StringComparison.CurrentCultureIgnoreCase) >= 0)
            {
                // ToolApp.exe /logdir "C:\Users\SCXSVC\Desktop\log\Web Service" /to v-tigong v-chqi /cc v-pexiao /subject TestApp
                Console.WriteLine("ToolApp.exe /LogDir logDir /To contact [contact2..] [/CC contact [contact2...]] [/Subject subject] [/User userName /Pwd password /Domain domain]");
                Console.WriteLine("TooApp.exe, XmlTransform.exe and MCFLogTemplate.xsl should be in the same folder!!");
                return;
            }

            string latestOpt = "";
            int paramIndex = 0;

            while (paramIndex < args.Count())
            {
                if (args[paramIndex].StartsWith(@"/"))
                {
                    latestOpt = args[paramIndex++];
                }

                switch (latestOpt.ToUpper())
                {
                    case "/LOGDIR":
                        logDir = args[paramIndex++];
                        break;
                    case "/SUBJECT":
                        subject = args[paramIndex++];
                        break;
                    case "/TO":
                        mailTo.Add(args[paramIndex++]);
                        break;
                    case "/CC":
                       mailCC.Add(args[paramIndex++]);
                        break;
                    case "/USER":
                        userName = args[paramIndex++];
                        break;
                    case "/PWD":
                        password = args[paramIndex++];
                        break;
                    case "/DOMAIN":
                        domain = args[paramIndex++];
                        break;
                    default:
                        Console.WriteLine("Illegal parameters!");
                        Console.WriteLine("ToolApp.exe /LogDir logDir /To contact [contact2..] [/CC contact [contact2...]] [/Subject subject]");
                        return;
                }
            }
           
            /*
            logDir = @"C:\Users\SCXSVC\Desktop\log\Web Service";
            mailTo.Add("v-tigong");
            mailTo.Add("v-chqi");
           
            mailCC.Add("v-tigong");
           */
     
            Tool tool = new Tool(logDir);
            tool.SendEmail(mailTo, mailCC, subject, userName, password, domain);
        }
    }
}
